//
//  RCCaculateIntegral.m
//  CPICApp
//
//  Created by sinosoft on 13-4-25.
//  Copyright (c) 2013年 lizhiwei. All rights reserved.
//

#import "RCCaculateIntegral.h"
#import "Config.h"
#import "RCAlertViewUtil.h"
#import "NSString+SBJson.h"
#import "NSObject+SBJson.h"
#import "AppDelegate.h"

@implementation RCCaculateIntegral

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}

-(id)initCaculateIntegalView
{
    self = [super init];
    return self;
}
-(void)setCaculatRequest:(NSString *)strServiceItem
{
    NSDictionary *dictUserInfo=[[NSUserDefaults standardUserDefaults] dictionaryForKey:DICT_USER_INFO];
    if (dictUserInfo!=nil) {
        if ([dictUserInfo valueForKey:@"UserAccount"]) {
            NSLog(@"%@",[dictUserInfo valueForKey:@"UserAccount"]);
        }
    }
    else
    {
        return;
    }
    
    NSMutableDictionary *dicRequest = [NSMutableDictionary dictionary];
    [dicRequest setObject:strServiceItem forKey:@"serviceItem"];
    [dicRequest setObject:[dictUserInfo valueForKey:@"UserAccount"] forKey:@"userAccount"];
    NSString *strRequestJson=[dicRequest JSONRepresentation];
    requestCaculate= [[ASIFormDataRequest alloc] initWithURL:[NSURL URLWithString:Server_Url_Form]];
    //设置需要POST的数据，这里提交两个数据，A=a&B=b
    [requestCaculate setPostValue:@"61001" forKey:@"RequestCode"];
    [requestCaculate setPostValue:strRequestJson forKey:@"RequestData"];
    
    [requestCaculate setDelegate:self];
    [requestCaculate setDidFailSelector:@selector(ResponseFail:)];
    [requestCaculate setDidFinishSelector:@selector(ResonseSuccess:)];
    [requestCaculate startAsynchronous];

    
}

- (void)ResonseSuccess:(ASIHTTPRequest *)request
{
    
    NSString *responseString = [request responseString];
    NSLog(@"responseString %@",responseString);
    NSMutableDictionary *dictResponse=[responseString JSONValue];
    NSLog(@"dictResponse  %@",dictResponse);
    
    NSMutableDictionary *jsonoSubObj = [dictResponse objectForKey:@"head"];
    NSString * ss = [[NSString alloc] initWithFormat:@"%@",[jsonoSubObj objectForKey:@"success"]];
    if ([ss isEqualToString:@"1"])
    {
        NSLog(@"后台成功计算分享模块的积分");
    }
    else
    {
      NSLog(@"后台计算积分失败");
    }
    [ss release];
}

- (void)ResponseFail:(ASIHTTPRequest *)request
{

    NSLog(@"服务器连接失败!");
    [self justShowMessage:@"服务器连接失败" title:@"注意"];
}

-(void)dealloc
{
    requestCaculate.delegate=nil;
    [super dealloc];
}

@end
